<template>
  <!-- 底部 -->
  <div class="my-footer">
    <!-- 全选 -->
    <div class="custom-control custom-checkbox">
      <input
        v-model="isSelect"
        type="checkbox"
        class="custom-control-input"
        id="footerCheck"
      />
      <label class="custom-control-label" for="footerCheck">全选</label>
    </div>
    <!-- 合计 -->
    <div>
      <span>合计:</span>
      <span class="price">¥ {{ sumPrice }}</span>
    </div>
    <!-- 按钮 -->
    <button type="button" class="footer-btn btn btn-primary">
      结算 ( {{ sumCount }} )
    </button>
  </div>
</template>

<script>
import {mapState, mapGetters} from 'vuex'

export default {
  // props: {
  //   goodsList: {
  //     type: Array,
  //     default() {
  //       return [];
  //     },
  //   },
  // },
  computed: {
    // 
    ...mapState(['list']),
    ...mapGetters(['count']),
    // // 获取已选中状态，返回一个数组
    // count() {
    //   return this.list.filter(item => item.goods_state);
    // },
    // 计算总个数
    sumCount() {
      return this.count
        .reduce((old, item) => old += item.goods_count , 0)
    },
    // 计算总价格
    sumPrice() {
      return this.count
        .reduce((old, item) => (old += item.goods_count * item.goods_price), 0)
        .toFixed(2);
    },
    // 全选
    isSelect: {
      set(val) {
        // this.$emit("selectAll", val);
        this.$store.commit('selectAll', val)
      },
      get() {
        return this.count.length === this.list.length
      },
    },
  },
};
</script>

<style lang="less" scoped>
.my-footer {
  position: fixed;
  z-index: 2;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background: #fff;

  .price {
    color: red;
    font-weight: bold;
    font-size: 15px;
  }
  .footer-btn {
    min-width: 80px;
    height: 30px;
    line-height: 30px;
    border-radius: 25px;
    padding: 0;
  }
}
</style>